using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Main.controls
{
    public partial class ShowPoll : System.Web.UI.UserControl
    {
        private int _pollId;
        public int PollID
        {
            get
            {
                return _pollId;
            }
            set
            {
                _pollId = value;
            }
        }
        /// <summary>
        /// The current Poll
        /// </summary>
        protected Poll currentPoll;
        /// <summary>
        /// Constructor that is possibly not needed...
        /// </summary>
        /// <remarks>I put this in with the hope of using the LoadControl(Type t, Object[] parameters)
        ///          method.  Unfortunately, it looks like that method is doesn't work all the 
        ///          time (according to msdn).  I'm not sure if it's needed anymore but you can never have
        ///          too many constructors!!!</remarks>
        public ShowPoll()
        {
            currentPoll = new Poll();
            PollID = 1;
        }
        /// <summary>
        /// Stuff to do when the page containing the control loads.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>Possibly might want to do some of this in another part of the page lifecycle.
        ///          Looking at http://msdn.microsoft.com/en-us/library/ms178472.aspx
        ///          it appears that PreInit might work.  I'm still not sure what all the various
        ///          stages are for, though.  For now this works.</remarks>        
        protected void Page_Load(object sender, EventArgs e)
        {
            // This following line will now be done on the page that loads the control.
            //     int test = Convert.ToInt32(Request.QueryString["id"]);
            // That page would then initialize its ShowPoll user control with the id before adding said
            // control to the content panel.
                currentPoll.FillByID(PollID);
                pollTitle.Text = currentPoll.Title;
                pollQuestion.Text = currentPoll.Question;
                pollSummary.Text = currentPoll.Summary;
                pollSummary.Text += currentPoll.Summary;
                pollSummary.Text += currentPoll.Summary;

                foreach (Option option in currentPoll.Options)
                {
                    pollOptions.InnerHtml += "\n<div class='pollOption'>\n";
                    pollOptions.InnerHtml += "\t<input id='" + option.OptionID.ToString() +
                                             "' value='" + option.OptionID + "' type='radio' name='option'"/*_" + option.OptionID + */ + "' />\n";

                    pollOptions.InnerHtml += "\t<label for='" + option.OptionID.ToString() + "'>" + option.PollOption + "</label>\n</div>";
                }
        }     
    }
}